package com.atgugui.eduorder.service.impl;

import com.atgugui.commonutils.ordervo.CourseWebVoOrder;
import com.atgugui.commonutils.ordervo.UcenterMemberOrder;
import com.atgugui.eduorder.client.EduClient;
import com.atgugui.eduorder.client.UcenterClient;
import com.atgugui.eduorder.entity.TOrder;
import com.atgugui.eduorder.mapper.TOrderMapper;
import com.atgugui.eduorder.service.TOrderService;
import com.atgugui.eduorder.utils.OrderNoUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2021-09-15
 */
@Service
public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements TOrderService {

    @Autowired
    private EduClient eduClient;

    @Autowired
    private UcenterClient ucenterClient;

    @Override
    public String createOrder(String courseId, String memberId) {
        CourseWebVoOrder courseInfo = eduClient.getCourseInfo(courseId);
        UcenterMemberOrder memberInfo = ucenterClient.getMemberInfo(memberId);
        //创建订单
        TOrder order = new TOrder();
        order.setOrderNo(OrderNoUtils.getOrderNo());
        order.setCourseId(courseId);
        order.setCourseTitle(courseInfo.getTitle());
        order.setCourseCover(courseInfo.getCover());
        order.setTeacherName(courseInfo.getTeacherName());
        order.setTotalFee(courseInfo.getPrice());
        order.setMemberId(memberId);
        order.setMobile(memberInfo.getMobile());
        order.setNickname(memberInfo.getNickname());
        order.setStatus(0);
        order.setPayType(1);
        /*无法自动填充创建订单时间和更新订单时间??????*/
        /*在TOrder表中的创建订单时间和更新订单时间上添加了自动填充注解，也扫描到了自动填充的配置类，但是仍然无法自动填充*/
        /*手动添加可以解决*/
        order.setGmtCreate(new Date());
        order.setGmtModified(new Date());
        baseMapper.insert(order);
        return order.getOrderNo();
    }
}
